package com.itbour.service.authority.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.authority.BackFuncInfoDao;
import com.itbour.dto.authority.BackFuncDto;
import com.itbour.dto.authority.FuncIds;
import com.itbour.service.authority.BackFuncInfoService;

public class BackFuncInfoServiceImpl implements BackFuncInfoService {
	
	private BackFuncInfoDao backFuncInfoDao;

	public BackFuncInfoDao getBackFuncInfoDao() {
		return backFuncInfoDao;
	}

	public void setBackFuncInfoDao(BackFuncInfoDao backFuncInfoDao) {
		this.backFuncInfoDao = backFuncInfoDao;
	}

	public void addBackFuncInfo(BackFuncDto backFuncDto) {
		Map<String, Object> parm=new HashMap<String, Object>();
		if(backFuncDto.getParent()==0){
			backFuncDto.setParent(null);
			parm.put("parent", backFuncDto.getParent());
		}else{
			parm.put("parent", backFuncDto.getParent());
		}
		parm.put("func_type", backFuncDto.getFunc_type());
		parm.put("name", backFuncDto.getName());
		parm.put("url", backFuncDto.getUrl());
		parm.put("desc", backFuncDto.getDesc());
		parm.put("update_by", backFuncDto.getUpdate_by());
		backFuncInfoDao.addBackFuncInfo(parm);
	}

	public Page pageBackFuncInfo(Integer pageNum, Integer pageSize,Map<String, Object> parm){
		/*
		 * pageNum 第几页 pageSize 一页几条数据 skipNum 起始位置Limit 0,10; totalSize 总共多少条数据
		 */
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNum, pageSize);// 获取起始位置
		int totalSize =backFuncInfoDao.getBackFuncInfCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNum = pageNum - 1;
		}
		// 分页检索
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<BackFuncDto> data = backFuncInfoDao.pageBackFuncInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}

	public void updBackFuncInfo(BackFuncDto backFuncDto) {
		Map<String, Object> parm=new HashMap<String, Object>();
		parm.put("func_id", backFuncDto.getFunc_id());
		parm.put("parent", backFuncDto.getParent());
		parm.put("order", backFuncDto.getOrder());
		parm.put("func_type", backFuncDto.getFunc_type());
		parm.put("name", backFuncDto.getName());
		parm.put("url", backFuncDto.getUrl());
		parm.put("desc", backFuncDto.getDesc());
		parm.put("update_by", backFuncDto.getUpdate_by());
		backFuncInfoDao.updBackFuncInfo(parm);
	}

	public List<BackFuncDto> selectOneBackFuncInfo(Map<String, Object> parm) {
		return backFuncInfoDao.getOneBackFuncInfo(parm);
	}

	@Override
	public void delBackFuncInfo(Map<String, Object> parm) {
		backFuncInfoDao.delBackFuncInfo(parm);
	}

	@Override
	public List<BackFuncDto> getParentInfo(Map<String, Object> parm) {
		return backFuncInfoDao.getParentInfo(parm);
	}

	@Override
	public List<FuncIds> getDelIds(Map<String, Object> parm) {
		return backFuncInfoDao.getDelIds(parm);
	}

	@Override
	public Set<Long> getFatherIds(Map<String, Object> parm) {
		return backFuncInfoDao.getFatherIds(parm);
	}

}
